#!/usr/bin/python
import sqlite3

conn = sqlite3.connect('test.db')
print("Opened database successfully")

# create table
c = conn.cursor()
# c.execute('''CREATE TABLE ROSTER
#        (ID INT PRIMARY KEY     NOT NULL,
#        NAME           TEXT    NOT NULL,
#        AGE            INT     NOT NULL,
#        ADDRESS        CHAR(50),
#        SALARY         REAL);''')
# print("Table created successfully")
# conn.commit()

# insert
# c.execute("INSERT INTO ROSTER (ID,NAME,AGE,ADDRESS,SALARY) \
#       VALUES (1, 'Paul', 32, 'California', 20000.00 )")

# c.execute("INSERT INTO ROSTER (ID,NAME,AGE,ADDRESS,SALARY) \
#       VALUES (2, 'Allen', 25, 'Texas', 15000.00 )")

# c.execute("INSERT INTO ROSTER (ID,NAME,AGE,ADDRESS,SALARY) \
#       VALUES (3, 'Teddy', 23, 'Norway', 20000.00 )")

# c.execute("INSERT INTO ROSTER (ID,NAME,AGE,ADDRESS,SALARY) \
#       VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 )")

# conn.commit()
# print("Records created successfully")


# select 
cursor = c.execute("SELECT id, name, address, salary  from ROSTER")
for row in cursor:
   print("ID = ", row[0])
   print("NAME = ", row[1])
   print("ADDRESS = ", row[2])
   print("SALARY = ", row[3], "\n")

print("ROSTER ---------- Operation done successfully\r\n\r\n\r\n")

cursor = c.execute("SELECT id, name, address, salary  from COMPANY")
for row in cursor:
   print("ID = ", row[0])
   print("NAME = ", row[1])
   print("ADDRESS = ", row[2])
   print("SALARY = ", row[3], "\n")

print("COMPANY ---------- Operation done successfully\r\n\r\n\r\n")

# delete 
# c.execute("DELETE from ROSTER where ID=2;")
# conn.commit()
# print ("Total number of rows deleted :", conn.total_changes)

# cursor = conn.execute("SELECT id, name, address, salary  from ROSTER")
# for row in cursor:
#    print("ID = ", row[0])
#    print ("NAME = ", row[1])
#    print ("ADDRESS = ", row[2])
#    print ("SALARY = ", row[3], "\n")

# print("Operation done successfully")


#update 
# c.execute("UPDATE ROSTER set SALARY = 25000.00 where ID=1")
# conn.commit()
# print ("Total number of rows updated :", conn.total_changes)

# cursor = conn.execute("SELECT id, name, address, salary  from ROSTER")
# for row in cursor:
#    print("ID = ", row[0])
#    print ("NAME = ", row[1])
#    print ("ADDRESS = ", row[2])
#    print ("SALARY = ", row[3], "\n")

# print ("--------- Operation done successfully")


conn.close()